import { create } from 'zustand'
import { persist } from 'zustand/middleware'
import { MenuItem } from '@/types'

interface GlobalState {
  token: string
  menus: MenuItem[]
  darkMode: boolean
  collapsed: boolean
}

interface Action {
  setToken: (key: GlobalState['token']) => void
  clearToken: () => void
  setMeuns: (menus: GlobalState['menus']) => void
  setDarkMode: (darkMode: GlobalState['darkMode']) => void
  setCollapsed: (collapsed: GlobalState['collapsed']) => void
}

export const useGlobalStore = create<GlobalState & Action>()(
  persist(
    (set) => ({
      token: '',
      menus: [],
      darkMode: false,
      collapsed: true,
      setToken: (token) => set({ token }),
      clearToken: () => set({ token: '' }),
      setMeuns: (menus) => set({ menus }),
      setDarkMode: (darkMode) => set({ darkMode }),
      setCollapsed: (collapsed) => set({ collapsed })
    }),
    {
      name: 'globalStore'
    }
  )
)
